﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using ESOL.Common.Entity;
using System.Data;

namespace ESOL.Services
{
    [ServiceContract]
    public interface IInvService
    {
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool TestConnect();

        #region 仓库，储位
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainWh AddInvWh(InvMaintainWh mwh);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainWh SaveInvWh(InvMaintainWh mwh);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainWh UpdateInvWh(InvMaintainWh mwh);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvWh(InvMaintainWh mwh);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvWhAllDsByCondition(InvWhQueryCondition qryCon);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvWhEntity GetInvWhEntityByKey(string whId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainWh GetInvMaintainWhByKey(string whId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvWhEntity> GetInvWhAllList();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvWhEntity> GetInvWhUnlockAllList();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddInvLoc(string userNo,InvWhLocationEntity loc);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddInvLocs(string userNo, List<InvWhLocationEntity> locs);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateInvLoc(InvWhLocationEntity loc);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvLoc(InvWhLocationEntity loc);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvLoc(string userNo, InvWhLocationEntity loc);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvWhLocationEntity> GetInvLocsByWhId(string whId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvLocsDsByWhId(string whId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvLocsDsByMtrlId(string mtrlId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvLocsDsByCodition(string codition);
        #endregion
        
        #region  //入库申请GetProdInventoryItems

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainIApp AddInvIApp(InvMaintainIApp miapp, DataSet iappis);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainIApp UpdateInvIApp(InvMaintainIApp miapp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvIApp(InvMaintainIApp miapp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvIAppEntity(InvIappEntity iapp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvIAppiEntity(InvIappiEntity iappi);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? SaveInvIAppi(InvIappiEntity iappi);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? SaveInvIAppis(DataSet iappis);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvIApp(InvIappSaveParam param);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainIApp GetInvMaintainIAppByKey(string appId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvIAppiAllDsByAppId(string appId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvIAppAllDsByCondition(InvIAppQueryCondition con);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvIAppItemDto> GetInvIAppItemsDtoByAppId(string appId);

        //入库单
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainIo InvIappToIo(InvMaintainIApp iapp, DataSet iappis);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainIo AddInvIo(InvMaintainIo mio, List<InvMaintainIoi> iois);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainIo UpdateInvIo(InvMaintainIo mio);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvIo(InvMaintainIo mio);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvIoEntity(InvIoEntity io);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvIoiEntity(InvIoiEntity ioi);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvIoisDs(DataSet iois);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvIoisList(List<InvMaintainIoi> iois);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvIoAllDsByCondition(InvIoQueryCondition con);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvMaintainIoi> GetInvIoiAllListByIoId(string ioId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvIoiAllDsByIoId(string ioId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainIo GetInvMaintainIoByKey(string ioId);

        /// <summary>
        /// 获取自动分配的库位
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvMaintainIoi> AutoAssignLocation(string userNo, List<InvMaintainIoi> items);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvWhLocationExEntity GetWhLocationExByKey(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateWhLocationEx(InvLocationExUpdateParam param);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool DelWhLocationEx(InvLocationExDelParam param);

        /// <summary>
        /// 入库
        /// 更新库存表
        /// 按库存类型，更新库位关系表
        /// 更新库存历史明细表
        /// </summary>
        /// <param name="userNo"></param>
        /// <param name="ds"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvStockInResultMessage StockIn(string userNo, List<InvMaintainIoi> items);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvProdInventoryEntity AddProdInventory(InvProdInventoryEntity prodInventory, List<InvProdInventoryItemEntity> invItems);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvProdInventoryEntity UpdateProdInventory(InvProdInventoryEntity prodInventory, List<InvProdInventoryItemEntity> invItems);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvProdInventoryEntity DeleteProdInventory(InvProdInventoryEntity prodInventory);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvProdInventoryEntity GetProdInventory(InvProdInventoryEntity prodInventory);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvProdInventoryItemEntity> GetProdInventoryItems(InvProdInventoryEntity prodInventory);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvProdInventoryEntity> GetProdInventoryList(InvProdInventoryEntity prodInventory);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        decimal GetAllowInventoryMaxQty(string woNo, string transNo, string technicItemId, string curWorkgroupNo);
       
        #endregion

        /// <summary>
        /// 查询库存
        /// </summary>
        /// <param name="con"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetStgAllDsByCondition(InvStgQueryCondition con);

        #region 盘点申请
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainCApp AddInvCApp(InvMaintainCApp capp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainCApp UpdateInvCApp(InvMaintainCApp capp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvCApp(InvMaintainCApp capp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvCAppEntity(InvCappEntity capp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainCApp GetMaintainCAppByKey(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetCAppAllDsByCondition(InvCAppQueryCondition con);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvCoEntity CAppToCo(string userNo, InvMaintainCApp capp);

        //盘点单

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainCo AddInvCo(InvMaintainCo co);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainCo UpdateInvCo(InvMaintainCo co);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvCo(InvMaintainCo co);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvCoi(InvMaintainCoi coi);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvCoiList(List<InvMaintainCoi> coi);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainCo GetMaintainCoByKey(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetCoAllDsByCondition(InvCoQueryCondition con);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvMaintainCoi> GetCoiAllListByCoId(string coId);

        /// <summary>
        /// 检查盘库时库位仓储类型
        /// 暂时不检查库位空间是否足够
        /// </summary>
        /// <param name="userNo"></param>
        /// <param name="locId"></param>
        /// <param name="productId"></param>
        /// <param name="qty"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string CheckLocation(string userNo, string locId, string productId, decimal qty);

        /// <summary>
        /// 盘库
        /// 更新库存表、历史
        /// </summary>
        /// <param name="coi"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? MakeInv(string userNo, List<InvMaintainCoi> coi);
        #endregion

        #region 出库
        //出库
        //出库申请
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddInvOapp(string userNo, InvOappEntity app);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateInvOapp(string userNo, InvOappEntity app);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvOapp(InvOappEntity app);
                
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvOapp(InvOAppSaveParam param);
        
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvOappEntity GetInvOappByKey(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainOApp GetInvMaintainOAppByKey(string appId);
        
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvOAppAllDsByCondition(InvOAppQueryCondition con);

        //出库申请单明细
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvOAppItemDto> GetInvOAppItemDtoAllListByAppId(string appId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvOAppiAllDsByAppId(string appId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvOAppiEntity(InvOappiEntity appi);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvOAppi(InvOappiEntity appi);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvOAppis(DataSet appi);



        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainOo InvOAppToOo(string userNo, InvOappEntity app, List<InvOAppItemDto> items);

        //出库单
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddInvOo(string userNo, InvOoEntity oo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateInvOo(string userNo, InvOoEntity oo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvOo(InvOoEntity oo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelInvOoDto(InvOoDto dto);

        //保存出库单
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? SaveInvOo(InvOoSaveParam param);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? SaveInvOois(DataSet ooi);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvOoEntity GetInvOoByKey(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetInvOoAllDsByCondition(InvOoQueryCondition con);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvOoPageResult GetInvOoAllListByCondition(InvOoQueryCondition con);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvMaintainOoi> GetInvOoiAllListByOoId(string ooId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetAllDsByOoId(string ooId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainOo GetInvMaintainOoByKey(string ooId);

        //出库结算
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string InvOutput(InvMaintainOo oo,List<InvMaintainOoi> oois);

        //出库单明细
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvOoItemDto> GetInvOoItemDtoAllListByOoId(string ooId);

        //自动分配出库库位
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvOoItemDto> AutoAssignOutLocation(InvAutoAssignOutLocationParam param);

        //出库
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvStockOutResultMessage StockOut(string userNo, List<InvOoItemDto> itemsDto);

        //InvWhItemEx
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvWhItemExDto> GetInvWhItemExDtoAllListByWhId(string whId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool SaveInvWhItemExDto(List<InvWhItemExDto> param);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool DelInvWhItemExDto(InvWhItemExDto dto);

        #endregion
        
        #region 工单领退料交易
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainMtrlTrans GetInvMtrlTransById(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvMaintainMtrlTrans> GetInvMtrlTransByCondition(InvMtrlTransQueryCondition condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<InvMtrlTransItemEntity> GetInvMtrlTransItemByTransNo(string transNo);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainMtrlTrans AddInvMtrlTransAndItem(InvMaintainMtrlTrans mtrlRequisition, List<InvMtrlTransItemEntity> Mtrls);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvMaintainMtrlTrans UpdateInvMtrlTransAndItem(InvMaintainMtrlTrans mtrlRequisition, List<InvMtrlTransItemEntity> Mtrls);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool DeleteInvMtrlTransAndItem(InvMaintainMtrlTrans mtrlRequisition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string InvOutWfStart(InvMaintainOApp trans);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string InvInWfStart(InvMaintainIApp trans);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        decimal GetAllowReqMaxQty(string woNo, string transNo, string mtrlId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        decimal GetAllowReturnMaxQty(string woNo, string transNo, string mtrlCode);
        #endregion

    }
}
